import * as types from '../types'
import api from '../../fetch/api'

const state = {
	houseTypedata: [],
	carouseldata: [],
	blocksData: [],
	startDate:"1", //入住的天数
	endDate:"", //离店的天数
	NumDate:'', //共多少晚
	dateshow:true,//搜索时段是否显示
	minprice:0,//最低价格
	maxprice:500,//最高价格
	pricemaxtit:"价格",//价格高低文案
	istxtactive:false,//价格字体颜色
	mykeydata:'',
}

const actions = {
	getBlocksData({commit}, data) {
		api.GetBlocks(data)
		.then(res => {
			let ajaxdata = res.result;
			commit(types.HOUSE_BLOCKS_DATA, ajaxdata);
		})
	},
	getstartDate({commit}, data) {
				commit(types.PUBLIC_STARTDATE, data);
	},
	getendDate({commit}, data) {
				commit(types.PUBLIC_ENDDATE, data);
	},
	getNumDate({commit}, data) {
				commit(types.PUBLIC_NUMDATE, data);
	},
	getdateshow({commit}, data) {
				commit(types.PUBLIC_DATESHOW, data);
	},
	setminprices({commit}, data) {
				commit(types.PUBLIC_MINPRICE, data);
	},
	setmaxprices({commit}, data) {
				commit(types.PUBLIC_MAXPRICE, data);
	},
	setpricemaxtit({commit}, data) {
				commit(types.PUBLIC_PRICEMAXTIT, data);
	},
	setistxtactive({commit}, data) {
				commit(types.PUBLIC_ISTXTACTIVE, data);
	},
	getmykey({commit}, data) {
				commit(types.PUBLIC_MYKEY, data);
	},
	getColumnData({commit}, data) {
		api.GetColumn(data)
		.then(res => {
			let ajaxdata = res.result;
			if(ajaxdata.column.length == 0) {
				commit(types.HOUSE_HOUSETYPE_DATA, false);
			} else {
				commit(types.HOUSE_HOUSETYPE_DATA, ajaxdata.column);
			}
			if(ajaxdata.carousel.length == 0) {
				commit(types.HOUSE_CAROUSEL_DATA, false);
			} else {
				commit(types.HOUSE_CAROUSEL_DATA, ajaxdata.carousel);
			}
		})
	},
}

const getters = {
	blocksData: state => state.blocksData,
	houseTypedata: state => state.houseTypedata,
	carouseldata: state => state.carouseldata,
	startDate: state => state.startDate,
	endDate: state => state.endDate,
	NumDate: state => state.NumDate,
	dateshow: state => state.dateshow,
	minprice: state => state.minprice,
	maxprice: state => state.maxprice,
	pricemaxtit: state => state.pricemaxtit,
	istxtactive: state => state.istxtactive,
	mykeydata: state => state.mykeydata,
}

const mutations = {
	[types.HOUSE_BLOCKS_DATA](state, res) {
		state.blocksData = res
	},
	[types.HOUSE_HOUSETYPE_DATA](state, res) {
		state.houseTypedata = res
	},
	[types.HOUSE_CAROUSEL_DATA](state, res) {
		state.carouseldata = res
	},
	[types.PUBLIC_STARTDATE](state, res) {
		state.startDate = res
	},
	[types.PUBLIC_ENDDATE](state, res) {
		state.endDate = res
	},
	[types.PUBLIC_NUMDATE](state, res) {
		state.NumDate = res
	},
	[types.PUBLIC_DATESHOW](state, res) {
		state.dateshow = res
	},
	[types.PUBLIC_MINPRICE](state, res) {
		state.minprice = res
	},
	[types.PUBLIC_MAXPRICE](state, res) {
		state.maxprice = res
	},
	[types.PUBLIC_PRICEMAXTIT](state, res) {
		state.pricemaxtit = res
	},
	[types.PUBLIC_ISTXTACTIVE](state, res) {
		state.istxtactive = res
	},
	[types.PUBLIC_MYKEY](state, res) {
		state.mykeydata = res
	},
}

export default {
	state,
	actions,
	getters,
	mutations
}